<template>
<div>
  <Tou></Tou>
  <second/><br><br>
  <el-group v-model="radio1">
    <el-button @click="finduserorder">全部订单</el-button>
    <el-button @click="zero" >未支付</el-button>
    <el-button @click="one">已支付</el-button>
    <el-button @click="two" >已退款</el-button>

  </el-group>

<!-- <button @click="zero">未支付</button><button @click="one">已支付</button>-->
  <el-table
    :data="order"
    style="width: 100%"
    :row-class-name="tableRowClassName">
    <el-table-column
      prop="horderId"
      label="订单编号"
      width="180">
    </el-table-column>
    <el-table-column
      prop="horderName"
      label="酒店名称"
      width="180">
    </el-table-column>
    <el-table-column
      prop="horderBname"
      label="房型"
      width="180">
    </el-table-column>
    <el-table-column
      prop="horderUname"
      label="租客"
      width="180">
    </el-table-column>
    <el-table-column
      prop="horderTel"
      label="电话"
      width="180">
    </el-table-column>
    <el-table-column
      prop="horderTime"
      label="日期"
      width="180">
    </el-table-column>
    <el-table-column
      prop="horderPrice"
      label="价格"
      width="180">
    </el-table-column>
    <el-table-column
      prop="horderFlag"
      label="状态">
      <template slot-scope="scope"> {{
        scope.row.horderFlag === 2 ? '已退款' : ( scope.row.horderFlag === 1 ? '已支付' : '未支付')
        }}
      </template>
    </el-table-column>
    <el-table-column
      label="操作">
      <template slot-scope="scope">
        <el-button @click="romorder(scope.row.horderId)" v-if="scope.row.horderFlag == 0" type="danger" round>取消预订</el-button>
        <el-button @click="delorder(scope.row.horderId)" v-if="scope.row.horderFlag == 1" type="warning" round>删除订单</el-button>
        <el-button @click="delorder(scope.row.horderId)" v-if="scope.row.horderFlag == 2" type="warning" round>删除订单</el-button>
        <el-button v-if="scope.row.horderFlag == 2" type="info" round disabled>凑位置的</el-button>
        <el-button @click="tuikuan(scope.row.horderId,scope.row.horderPrice)" v-if="scope.row.horderFlag == 1" type="primary" round>申请退款</el-button>
        <el-button @click="topay(scope.row.horderId,scope.row.horderPrice)" v-if="scope.row.horderFlag == 0" type="primary" round>Go去支付</el-button>
      </template>
    </el-table-column>
  </el-table>

</div>


</template>

<script>
import Second from "./second.vue";
import Tou from "./tou.vue";

export default {
  name: "hotelorder",
  components: {Tou, Second},
  data() {
    return {
      radio1:'',
      order:[],
      formdiv:''
    }

  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    finduserorder(){
      var uuid=localStorage.getItem("token")
      this.$axios.get("/hotelorder/findallorder",{
        params:{
          uuid:uuid
        }
      }).then(data=>{
        this.order=data.data.data
      })
    },
    zero(){
      var uuid=localStorage.getItem("token")
      this.$axios.get("/hotelorder/zero",{
        params:{
          uuid:uuid
        }
      }).then(data=>{
        this.order=data.data.data
      })
    },
    one(){
      var uuid=localStorage.getItem("token")
      this.$axios.get("/hotelorder/one",{
        params:{
          uuid:uuid
        }
      }).then(data=>{
        this.order=data.data.data
      })
    },
    two(){
      var uuid=localStorage.getItem("token")
      this.$axios.get("/hotelorder/two",{
        params:{
          uuid:uuid
        }
      }).then(data=>{
        this.order=data.data.data
      })
    },
    romorder(id){
      this.$axios.delete("/hotelorder/deletenotpayorder",{params:{
          horderId:id
        }}).then(data=>{
          if (data.data.code==200){
                alert("取消成功")
            this.finduserorder()
          }else {
            alert("取消失败")
          }
      })
    },
    delorder(id){
      this.$axios.delete("/hotelorder/deletepayorder",{params:{
          horderId:id
        }}).then(data=>{
          if (data.data.code==200){
            alert("移除成功")
            this.finduserorder()
          }else {
            alert("移除失败")
          }
      })
    },
    topay(horderId,horderPrice){
      this.$axios.post("/hotelorder/hotelordertopay",{
        horderId:horderId,
        horderPrice:horderPrice
      }).then(data=>{
        if (data.data.code==200){
          this.formdiv=data.data.data;
          this.$router.push({path:'/pay',query:{url:data.data.data}})
        }else {
          alert("支付失败")
        }
      })
    },
    tuikuan(horderId,horderPrice){
      this.$axios.post("/hotelorder/tuimoney",{
        horderId:horderId,
        horderPrice:horderPrice
      }).then(data=>{
        if (data.data.code==200){
          this.finduserorder()
          alert("退款成功")
        }else {
          alert(data.data.msg)
        }
      })
    }

  },
  mounted() {
    this.finduserorder()
  }
}
</script>

<style scoped>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
